package com.enjoy.xbase.common;

import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;

/**
 * 描述：循环 PagerAdapter
 */
public abstract class LoopPagerAdapter extends PagerAdapter {
    private static int middle = 50000;

    public static int getCount(int icount, int size) {
        if (size <= 0) return -1;
        int temp = icount - middle;
        temp %= size;
        if (temp < 0) {
            temp = size + temp;
        }
        return temp;
    }

    @Override
    public final int getCount() {
        return middle * 2;
    }

    public int getMiddle() {
        return middle;
    }

    public int getCount(int icount) {
        int size = getSize();
        if (size <= 0) return -1;
        int temp = icount - middle;
        temp %= size;
        if (temp < 0) {
            temp = size + temp;
        }
        return temp;
    }

    public abstract int getSize();


    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    // 来判断显示的是否是同一张图片，这里我们将两个参数相比较返回即可
    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        boolean simple = arg0 == arg1;
        return simple;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        (container).removeView((View) object);
    }
}
